package com.flurry.android;

import android.content.Context;
import android.os.AsyncTask.Status;
import android.util.Pair;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

final class aa
{
  private static String bm = aa.class.getSimpleName();
  private final Map<Pair<String, Integer>, List<AdUnit>> bn = new HashMap();
  private bi bo;

  private static boolean a(List<AdUnit> paramList)
  {
    return (paramList == null) || (paramList.size() == 0) || (((AdUnit)paramList.get(0)).getAdFrames().size() == 0) || (((AdFrame)((AdUnit)paramList.get(0)).getAdFrames().get(0)).getAdSpaceLayout() == null);
  }

  private boolean b(List<AdUnit> paramList)
  {
    if (paramList != null);
    try
    {
      if (paramList.size() < 2)
        if (this.bo != null)
        {
          boolean bool2 = this.bo.getStatus().equals(AsyncTask.Status.FINISHED);
          if (!bool2)
            break label49;
        }
      for (boolean bool1 = true; ; bool1 = false)
      {
        return bool1;
        label49: if (this.bo != null)
          this.bo.getStatus().equals(AsyncTask.Status.FINISHED);
      }
    }
    finally
    {
    }
  }

  private void c(Context paramContext, String paramString, int paramInt)
  {
    try
    {
      Pair localPair = Pair.create(paramString, Integer.valueOf(fl.u(paramContext)));
      List localList = (List)this.bn.get(localPair);
      FlurryAdSize localFlurryAdSize = FlurryAdSize.BANNER_BOTTOM;
      if (!a(localList))
        localFlurryAdSize = FlurryAdSize.a(((AdFrame)((AdUnit)localList.get(0)).getAdFrames().get(0)).getAdSpaceLayout());
      StringBuilder localStringBuilder;
      if (b(localList))
      {
        localStringBuilder = new StringBuilder().append("Starting AsyncAdTask from EnsureCacheNotEmpty size: ");
        if (localList == null)
          break label181;
      }
      label181: for (String str = Integer.toString(localList.size()); ; str = "")
      {
        localStringBuilder.append(str).append(" wait: ").append(Integer.toString(0)).toString();
        FlurryAds localFlurryAds = FlurryAds.getInstance();
        localFlurryAds.getClass();
        this.bo = new bi(localFlurryAds, paramContext, paramString, localFlurryAdSize);
        this.bo.execute(new Void[0]);
        return;
      }
    }
    finally
    {
    }
  }

  final void a(Context paramContext, String paramString, int paramInt)
  {
    try
    {
      Pair localPair = Pair.create(paramString, Integer.valueOf(fl.u(paramContext)));
      List localList = (List)this.bn.get(localPair);
      if (localList != null)
      {
        if ((paramInt > -1) && (paramInt <= localList.size()))
          break label81;
        this.bn.put(localPair, new ArrayList());
      }
      while (true)
      {
        c(paramContext, paramString, 0);
        return;
        label81: if (paramInt > 0)
        {
          localList.subList(0, paramInt).clear();
          this.bn.put(localPair, localList);
        }
      }
    }
    finally
    {
    }
  }

  final void a(Context paramContext, String paramString1, String paramString2)
  {
    try
    {
      Pair localPair = Pair.create(paramString1, Integer.valueOf(fl.u(paramContext)));
      List localList = (List)this.bn.get(localPair);
      if (localList != null)
      {
        Iterator localIterator = localList.iterator();
        while (localIterator.hasNext())
          if (((AdUnit)localIterator.next()).getGroupId().toString().equals(paramString2))
            localIterator.remove();
      }
    }
    finally
    {
    }
    c(paramContext, paramString1, 0);
  }

  final void a(Context paramContext, List<AdUnit> paramList)
  {
    synchronized (this.bn)
    {
      int i = fl.u(paramContext);
      new StringBuilder().append("putting ").append(paramList.size()).append(" orientation: ").append(i).toString();
      Iterator localIterator = paramList.iterator();
      if (localIterator.hasNext())
      {
        AdUnit localAdUnit = (AdUnit)localIterator.next();
        if (localAdUnit.getIdHash().length() > 0)
        {
          bl localbl = new bl(localAdUnit.getIdHash().toString(), localAdUnit.getServeTime().longValue(), localAdUnit.getExpirationTime().longValue(), localAdUnit.getNewCap().intValue(), localAdUnit.getPreviousCap().intValue(), localAdUnit.getPreviousCapType().intValue());
          ca.aq().a(localbl);
        }
        Pair localPair = Pair.create(localAdUnit.getAdSpace().toString(), Integer.valueOf(i));
        Object localObject2 = (List)this.bn.get(localPair);
        if (localObject2 == null)
          localObject2 = new ArrayList();
        ((List)localObject2).add(localAdUnit);
        this.bn.put(localPair, localObject2);
      }
    }
  }

  final AdUnit b(Context paramContext, String paramString)
  {
    while (true)
    {
      try
      {
        int i = fl.u(paramContext);
        Pair localPair1 = Pair.create(paramString, Integer.valueOf(i));
        List localList = (List)this.bn.get(localPair1);
        if (a(localList))
        {
          new StringBuilder().append("no valid ad units in cache for current orientation for ").append(paramString).toString();
          int j;
          if (i == 1)
          {
            j = 2;
            Pair localPair2 = new Pair(paramString, Integer.valueOf(j));
            localList = (List)this.bn.get(localPair2);
            if ((a(localList)) || (!((AdFrame)((AdUnit)localList.get(0)).getAdFrames().get(0)).getAdSpaceLayout().getFormat().equals("takeover")))
            {
              new StringBuilder().append("no valid ad units in cache for other orientation for ").append(paramString).toString();
              localAdUnit = null;
              return localAdUnit;
            }
          }
          else
          {
            j = 1;
            continue;
          }
        }
        if (!a(localList))
        {
          Iterator localIterator = localList.iterator();
          if (localIterator.hasNext())
          {
            localAdUnit = (AdUnit)localIterator.next();
            if ((!fl.g(localAdUnit.getExpiration().longValue())) || (localAdUnit.getAdFrames().size() <= 0))
              continue;
            localIterator.remove();
            new StringBuilder().append("found valid ad unit for ").append(paramString).toString();
            c(paramContext, paramString, 0);
            continue;
          }
        }
      }
      finally
      {
      }
      new StringBuilder().append("no valid ad units for ").append(paramString).toString();
      c(paramContext, paramString, 0);
      AdUnit localAdUnit = null;
    }
  }

  final List<AdUnit> b(Context paramContext, String paramString, int paramInt)
  {
    ArrayList localArrayList;
    try
    {
      Pair localPair = Pair.create(paramString, Integer.valueOf(fl.u(paramContext)));
      List localList = (List)this.bn.get(localPair);
      localArrayList = new ArrayList();
      if (localList != null)
      {
        Iterator localIterator = localList.iterator();
        while ((localIterator.hasNext()) && (localArrayList.size() <= paramInt))
        {
          AdUnit localAdUnit = (AdUnit)localIterator.next();
          if ((fl.g(localAdUnit.getExpiration().longValue())) && (localAdUnit.getCombinable().intValue() == 1) && (localAdUnit.getAdFrames().size() > 0))
          {
            localArrayList.add(localAdUnit);
            localIterator.remove();
          }
        }
      }
    }
    finally
    {
    }
    c(paramContext, paramString, 0);
    return localArrayList;
  }

  final boolean c(Context paramContext, String paramString)
  {
    try
    {
      Pair localPair = Pair.create(paramString, Integer.valueOf(fl.u(paramContext)));
      List localList = (List)this.bn.get(localPair);
      if (!a(localList))
      {
        Iterator localIterator = localList.iterator();
        boolean bool2;
        do
        {
          if (!localIterator.hasNext())
            break;
          bool2 = fl.g(((AdUnit)localIterator.next()).getExpiration().longValue());
        }
        while (!bool2);
      }
      for (boolean bool1 = true; ; bool1 = false)
        return bool1;
    }
    finally
    {
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.flurry.android.aa
 * JD-Core Version:    0.6.2
 */